package cn.itsource.pethome.order.controller;

import cn.itsource.pethome.basic.util.AjaxResult;
import cn.itsource.pethome.basic.util.UserContext;
import cn.itsource.pethome.order.service.IProductOrderService;
import cn.itsource.pethome.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 宠物订单controller
 */
@RestController
@RequestMapping("/productOrder")
public class ProductOrderController {
    //订单提交接口
    @Autowired
    private IProductOrderService productOrderService;
    /**
     * 宠物订单提交
     * @return
     */
    @PostMapping("/submitOrder")
    public AjaxResult submitOrder(@RequestBody Map<String,Object> param, HttpServletRequest request){

        try {
            //获取前台下单登录用户
            User loginUser = UserContext.getLoginUser(request);
            //提交订单  ,返回二维码界面表单
            String formHtml = productOrderService.submitOrder(param, loginUser);
            return new AjaxResult().setResult(formHtml);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, e.getMessage());
        }
    }


}
